/*
 * EditSettings.settings.java
 *
 * Created on August 8, 2007, 8:58 AM
 *
 * @author  pquiring
 */

import javaforce.*;
import java.awt.*;
import java.awt.event.*;

public class EditSettings extends javax.swing.JDialog {

  /** Creates new form EditSettings */
  private EditSettings(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
    setComponentOrientation(((parent == null) ? javax.swing.JOptionPane.getRootFrame() : parent).getComponentOrientation());
    if (parent != null) setLocationRelativeTo(parent);
    tX.setText("" + Settings.settings.cols);
    tY.setText("" + Settings.settings.rows);
    tScrollBack.setText("" + Settings.settings.scrollBack);
    sFontSize.setValue(Settings.settings.fontSize);
    fontWidth.setValue(Settings.settings.fontWidth);
    fontHeight.setValue(Settings.settings.fontHeight);
    fontDescent.setValue(Settings.settings.fontDescent);
    tForeColor.setText(Integer.toHexString(Settings.settings.foreColor.getRGB()).substring(2));
    tBackColor.setText(Integer.toHexString(Settings.settings.backColor.getRGB()).substring(2));
    tCursorColor.setText(Integer.toHexString(Settings.settings.cursorColor.getRGB()).substring(2));
    tSelectColor.setText(Integer.toHexString(Settings.settings.selectColor.getRGB()).substring(2));
    tTermType.setText(Settings.settings.termType);
    tTabStops.setText("" + Settings.settings.tabStops);
    termApp.setText(Settings.settings.termApp);
    setPosition();
  }

  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jLabel22 = new javax.swing.JLabel();
    jLabel1 = new javax.swing.JLabel();
    tX = new javax.swing.JTextField();
    jLabel2 = new javax.swing.JLabel();
    tY = new javax.swing.JTextField();
    jLabel3 = new javax.swing.JLabel();
    tScrollBack = new javax.swing.JTextField();
    jLabel4 = new javax.swing.JLabel();
    bSave = new javax.swing.JButton();
    bCancel = new javax.swing.JButton();
    sFontSize = new javax.swing.JSpinner();
    jLabel5 = new javax.swing.JLabel();
    tForeColor = new javax.swing.JTextField();
    jLabel6 = new javax.swing.JLabel();
    tBackColor = new javax.swing.JTextField();
    jLabel7 = new javax.swing.JLabel();
    tCursorColor = new javax.swing.JTextField();
    foreColorEdit = new javax.swing.JButton();
    backColorEdit = new javax.swing.JButton();
    cursorColorEdit = new javax.swing.JButton();
    jLabel8 = new javax.swing.JLabel();
    tTermType = new javax.swing.JTextField();
    jLabel9 = new javax.swing.JLabel();
    jLabel13 = new javax.swing.JLabel();
    tSelectColor = new javax.swing.JTextField();
    selectColorEdit = new javax.swing.JButton();
    jLabel14 = new javax.swing.JLabel();
    tTabStops = new javax.swing.JTextField();
    jLabel16 = new javax.swing.JLabel();
    termApp = new javax.swing.JTextField();
    jLabel17 = new javax.swing.JLabel();
    jLabel18 = new javax.swing.JLabel();
    jLabel19 = new javax.swing.JLabel();
    fontWidth = new javax.swing.JSpinner();
    fontHeight = new javax.swing.JSpinner();
    fontDescent = new javax.swing.JSpinner();
    jLabel10 = new javax.swing.JLabel();
    jLabel11 = new javax.swing.JLabel();
    jLabel12 = new javax.swing.JLabel();
    jLabel20 = new javax.swing.JLabel();
    jLabel21 = new javax.swing.JLabel();
    jLabel15 = new javax.swing.JLabel();

    jLabel22.setText("*");

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setTitle("Edit Settings");
    setModal(true);

    jLabel1.setText("Columns");

    tX.setText("80");
    tX.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        anykey(evt);
      }
    });

    jLabel2.setText("Rows");

    tY.setText("24");
    tY.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        anykey(evt);
      }
    });

    jLabel3.setText("Scroll Back");

    tScrollBack.setText("3000");
    tScrollBack.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        anykey(evt);
      }
    });

    jLabel4.setText("Font Size");

    bSave.setText("Save");
    bSave.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        bSaveActionPerformed(evt);
      }
    });

    bCancel.setText("Cancel");
    bCancel.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        bCancelActionPerformed(evt);
      }
    });

    sFontSize.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        anykey(evt);
      }
    });

    jLabel5.setText("Fore Color");

    tForeColor.setText("000000");
    tForeColor.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        anykey(evt);
      }
    });

    jLabel6.setText("Back Color");

    tBackColor.setText("ffffff");
    tBackColor.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        anykey(evt);
      }
    });

    jLabel7.setText("Cursor Color");

    tCursorColor.setText("0000ff");
    tCursorColor.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        anykey(evt);
      }
    });

    foreColorEdit.setText("...");
    foreColorEdit.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        foreColorEditActionPerformed(evt);
      }
    });

    backColorEdit.setText("...");
    backColorEdit.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        backColorEditActionPerformed(evt);
      }
    });

    cursorColorEdit.setText("...");
    cursorColorEdit.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        cursorColorEditActionPerformed(evt);
      }
    });

    jLabel8.setText("Term Type");

    tTermType.setText("xterm");
    tTermType.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        anykey(evt);
      }
    });

    jLabel9.setText("* - takes effect immediately");

    jLabel13.setText("Select Color");

    tSelectColor.setText("777777");
    tSelectColor.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        anykey(evt);
      }
    });

    selectColorEdit.setText("...");
    selectColorEdit.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        selectColorEditActionPerformed(evt);
      }
    });

    jLabel14.setText("Tab Stops");

    tTabStops.setText("8");
    tTabStops.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        anykey(evt);
      }
    });

    jLabel16.setText("Term App");

    termApp.setText("bash");
    termApp.setToolTipText("Terminal App (Linux only)");

    jLabel17.setText("Font X Adj");

    jLabel18.setText("Font Y Adj");

    jLabel19.setText("Font Base Adj");

    fontWidth.setModel(new javax.swing.SpinnerNumberModel(0, -4, 4, 1));

    fontHeight.setModel(new javax.swing.SpinnerNumberModel(0, -4, 4, 1));

    fontDescent.setModel(new javax.swing.SpinnerNumberModel(0, -4, 4, 1));

    jLabel10.setText("*");

    jLabel11.setText("*");

    jLabel12.setText("*");

    jLabel20.setText("*");

    jLabel21.setText("*");

    jLabel15.setText("*");

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(jLabel16)
          .addGroup(layout.createSequentialGroup()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(layout.createSequentialGroup()
                .addComponent(bSave)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bCancel))
              .addComponent(jLabel9)
              .addComponent(jLabel18)
              .addComponent(jLabel19)
              .addComponent(jLabel17)
              .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addComponent(jLabel1)
                  .addComponent(jLabel2)
                  .addComponent(jLabel3)
                  .addComponent(jLabel4)
                  .addComponent(jLabel5)
                  .addComponent(jLabel6)
                  .addComponent(jLabel7)
                  .addComponent(jLabel13)
                  .addComponent(jLabel8)
                  .addComponent(jLabel14))
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                  .addComponent(termApp)
                  .addComponent(tTabStops)
                  .addComponent(tTermType)
                  .addComponent(tSelectColor)
                  .addComponent(tCursorColor)
                  .addComponent(tBackColor)
                  .addGroup(layout.createSequentialGroup()
                    .addGap(1, 1, 1)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                      .addComponent(fontDescent)
                      .addComponent(tX)
                      .addComponent(tY)
                      .addComponent(tForeColor, javax.swing.GroupLayout.DEFAULT_SIZE, 92, Short.MAX_VALUE)
                      .addComponent(sFontSize)
                      .addComponent(tScrollBack)
                      .addComponent(fontWidth)
                      .addComponent(fontHeight))))))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(selectColorEdit, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addComponent(cursorColorEdit, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE)
                .addComponent(backColorEdit, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(foreColorEdit, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE))
              .addComponent(jLabel10)
              .addComponent(jLabel11)
              .addComponent(jLabel12)
              .addComponent(jLabel20)
              .addComponent(jLabel21)
              .addComponent(jLabel15))))
        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(tX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jLabel1))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(tY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jLabel2))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(tScrollBack, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jLabel3)
          .addComponent(jLabel15))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(sFontSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jLabel4)
          .addComponent(jLabel21))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(foreColorEdit)
          .addComponent(tForeColor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jLabel5))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel17)
          .addComponent(fontWidth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jLabel10))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel18)
          .addComponent(fontHeight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jLabel11))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel19)
          .addComponent(fontDescent, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jLabel12))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(backColorEdit)
          .addComponent(tBackColor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jLabel6))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(cursorColorEdit)
          .addComponent(tCursorColor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jLabel7))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(selectColorEdit)
          .addComponent(tSelectColor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jLabel13))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(tTermType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jLabel8))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel14)
          .addComponent(tTabStops, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jLabel20))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel16)
          .addComponent(termApp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jLabel9)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(bSave)
          .addComponent(bCancel))
        .addContainerGap())
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

  private void anykey(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_anykey
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) bSaveActionPerformed(null);
    if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) bCancelActionPerformed(null);
  }//GEN-LAST:event_anykey

  private void selectColorEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectColorEditActionPerformed
    Color tmp = new Color(JF.atox(tSelectColor.getText()));
    tmp = EditColor.editColor(this, tmp);
    tSelectColor.setText(Integer.toHexString(tmp.getRGB()).substring(2));
  }//GEN-LAST:event_selectColorEditActionPerformed

  private void foreColorEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_foreColorEditActionPerformed
    Color tmp = new Color(JF.atox(tForeColor.getText()));
    tmp = EditColor.editColor(this, tmp);
    tForeColor.setText(Integer.toHexString(tmp.getRGB()).substring(2));
  }//GEN-LAST:event_foreColorEditActionPerformed

  private void cursorColorEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cursorColorEditActionPerformed
    Color tmp = new Color(JF.atox(tCursorColor.getText()));
    tmp = EditColor.editColor(this, tmp);
    tCursorColor.setText(Integer.toHexString(tmp.getRGB()).substring(2));
  }//GEN-LAST:event_cursorColorEditActionPerformed

  private void backColorEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backColorEditActionPerformed
    Color tmp = new Color(JF.atox(tBackColor.getText()));
    tmp = EditColor.editColor(this, tmp);
    tBackColor.setText(Integer.toHexString(tmp.getRGB()).substring(2));
  }//GEN-LAST:event_backColorEditActionPerformed

  private void bSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bSaveActionPerformed
    if (!validFields()) return;
    Settings.settings.cols = JF.atoi(tX.getText());
    Settings.settings.rows = JF.atoi(tY.getText());
    Settings.settings.scrollBack = JF.atoi(tScrollBack.getText());
    Settings.settings.fontSize = ((Integer)sFontSize.getValue()).intValue();
    Settings.settings.fontWidth = (Integer)fontWidth.getValue();
    Settings.settings.fontHeight = (Integer)fontHeight.getValue();
    Settings.settings.fontDescent = (Integer)fontDescent.getValue();
    Settings.settings.foreColor = new Color(JF.atox(tForeColor.getText()));
    Settings.settings.backColor = new Color(JF.atox(tBackColor.getText()));
    Settings.settings.cursorColor = new Color(JF.atox(tCursorColor.getText()));
    Settings.settings.selectColor = new Color(JF.atox(tSelectColor.getText()));
    Settings.settings.termType = tTermType.getText();
    Settings.settings.tabStops = JF.atoi(tTabStops.getText());
    Settings.settings.termApp = termApp.getText();
    Settings.settings.saveSettings();
    dispose();
  }//GEN-LAST:event_bSaveActionPerformed

  private void bCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bCancelActionPerformed
    dispose();
  }//GEN-LAST:event_bCancelActionPerformed

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton bCancel;
  private javax.swing.JButton bSave;
  private javax.swing.JButton backColorEdit;
  private javax.swing.JButton cursorColorEdit;
  private javax.swing.JSpinner fontDescent;
  private javax.swing.JSpinner fontHeight;
  private javax.swing.JSpinner fontWidth;
  private javax.swing.JButton foreColorEdit;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel10;
  private javax.swing.JLabel jLabel11;
  private javax.swing.JLabel jLabel12;
  private javax.swing.JLabel jLabel13;
  private javax.swing.JLabel jLabel14;
  private javax.swing.JLabel jLabel15;
  private javax.swing.JLabel jLabel16;
  private javax.swing.JLabel jLabel17;
  private javax.swing.JLabel jLabel18;
  private javax.swing.JLabel jLabel19;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel20;
  private javax.swing.JLabel jLabel21;
  private javax.swing.JLabel jLabel22;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JLabel jLabel4;
  private javax.swing.JLabel jLabel5;
  private javax.swing.JLabel jLabel6;
  private javax.swing.JLabel jLabel7;
  private javax.swing.JLabel jLabel8;
  private javax.swing.JLabel jLabel9;
  private javax.swing.JSpinner sFontSize;
  private javax.swing.JButton selectColorEdit;
  private javax.swing.JTextField tBackColor;
  private javax.swing.JTextField tCursorColor;
  private javax.swing.JTextField tForeColor;
  private javax.swing.JTextField tScrollBack;
  private javax.swing.JTextField tSelectColor;
  private javax.swing.JTextField tTabStops;
  private javax.swing.JTextField tTermType;
  private javax.swing.JTextField tX;
  private javax.swing.JTextField tY;
  private javax.swing.JTextField termApp;
  // End of variables declaration//GEN-END:variables

  public static void editSettings(java.awt.Frame parent) {
    EditSettings dialog = new EditSettings(parent, true);
    dialog.setVisible(true);
  }

  private boolean validFieldNumber(String str, int min, int max) {
    if (!validField(str)) return false;
    for(int a=0;a<str.length();a++) if ((str.charAt(a) < '0') || (str.charAt(a) > '9')) return false;
    int value = JF.atoi(str);
    if ((value < min) || (value > max)) return false;
    return true;
  }

  private boolean validFieldHexNumber(String str) {
    if (!validField(str)) return false;
    if (str.length() != 6) return false;
    for(int a=0;a<str.length();a++) {
      if (
        ((str.charAt(a) < '0') || (str.charAt(a) > '9')) &&
        ((str.charAt(a) < 'A') || (str.charAt(a) > 'F')) &&
        ((str.charAt(a) < 'a') || (str.charAt(a) > 'f')) )
        return false;
    }
    return true;
  }

  private boolean validField(String str) {
    if (str.length() == 0) return false;
    if (str.indexOf('\"') != -1) return false;
    if (str.indexOf('\'') != -1) return false;
    return true;
  }
  public final static int MIN = 16;
  public final static int MAX = 256;
  private boolean validFields() {
    if (!validFieldHexNumber(tBackColor.getText())) {JFAWT.showError("Invalid field", "Back Color is not valid"); return false;}
    if (!validFieldHexNumber(tForeColor.getText())) {JFAWT.showError("Invalid field", "Fore Color is not valid"); return false;}
    if (!validFieldHexNumber(tCursorColor.getText())) {JFAWT.showError("Invalid field", "Cursor Color is not valid"); return false;}
    if (!validFieldHexNumber(tSelectColor.getText())) {JFAWT.showError("Invalid field", "Select Color is not valid"); return false;}
    if (!validFieldNumber(tScrollBack.getText(), 0, 65535)) {JFAWT.showError("Invalid field", "ScrollBack must be >=0 and <=65535"); return false;}
    if (!validFieldNumber(tTabStops.getText(), 1, 8)) {JFAWT.showError("Invalid field", "TabStops must be >=1 and <=8"); return false;}
    if (!validFieldNumber(tX.getText(), MIN, MAX)) {JFAWT.showError("Invalid field", "cols must be >=16 and <=255"); return false;}
    if (!validFieldNumber(tY.getText(), MIN, MAX)) {JFAWT.showError("Invalid field", "rows must be >=16 and <=255"); return false;}
    if (!validField(tTermType.getText())) {JFAWT.showError("Invalid field", "TermType must not be empty"); return false;}
    return true;
  }

  private void setPosition() {
    Dimension d = getSize();
    Rectangle s = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
    if ((d.width > s.width) || (d.height > s.height)) {
      if (d.width > s.width) d.width = s.width;
      if (d.height > s.height) d.height = s.height;
      setSize(d);
    }
    setLocation(s.width/2 - d.width/2, s.height/2 - d.height/2);
  }
}
